<?php 
  ob_start();
  session_start(); 
  include "inc/conn.php";
  $tts = date("YmdHis",time());
  // $tts = date("Y-m-d H:i:s",time());
  $qd_desc = "客户向工作人员出示报名成功的二维码或提供手机号";
  
?>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes" />
<title>扫码核销</title>
<meta name="author" content="andy - vip@d163.net">
<meta name="copyright" content="www.d163.net">
<link href="https://lib.baomitu.com/twitter-bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="http://at.alicdn.com/t/font_374778_ixtunt1c0v.css">
<link href="inc/css/wap.css?v=<?php echo $tts;?>" rel="stylesheet" type="text/css" />
<script src="inc/js/ajax_wap.js?v=<?php echo $tts;?>" type="text/javascript"></script>
<style>
  .top-ico .iconfont {font-size: 94px; color: #09BB07; }
  .top-ico {text-align: center; }
  .msg-box-txt {text-align: center; }
  .top-ico .iconfont.icon-warn {color: red; }
  .manage {position: absolute; right: 6px; top: 1px; }
  .manage .iconfont {color: #ffffff; font-size: 23px; }
  .sub_top{display: none;}
  .span_cnzz {position: fixed; bottom: 0; left: 0; visibility: hidden; }
  #scanqrcode1 {
    margin: 10px auto 0;
    text-align: center;
    width: 40%;
  }

  #scanqrcode1 .iconfont {
    font-size: 120px;
    color: #ffffff;
  }
  #scanqrcode1 span {
    color: #ffffff;
    text-align: center;
    display: block;
    margin-top: -30px;
  }
  .myform input[type='submit']{
    margin-top: 10px;
  }
  .foot, .foot a{color: #FF9800;}
  .toggle-nav:visited, .toggle-nav:hover{color: #ffffff;transform: rotateZ(180deg);}
  
</style>
<body onLoad="inst();">
<div class="bgcard"></div>

<?php 

if(isset($_SESSION['pwd']) && $_SESSION['pwd'] == $password){
  // header("location:scan.php?v={$tts}");
}else{
  // header("location:login.php?v={$tts}");
  // header('Refresh: 2; url=login.php');
  echo "<script>alert('请先登录');window.location.href='login.php'</script>";
  exit;
  
  
}


$stime=microtime(true); 
$codes = trim($_POST['code']);
$shujus = trim($_POST['txt_data']);
$shuru1 = trim($_POST['name']);
$time_creat = date("Y-m-d H:i:s",time());

$pwd = $_SESSION['pwd'];
$tj = isset($_GET['tj'])?$_GET['tj']:"";
if($tj == 'logout'){
    session_start(); //开启session
    session_destroy();  //注销session
    header("location:login.php?v={$tts}"); //跳转到首页

}
if($pwd==$password){
if($shujus != 1){
?>
<?php include 'menu.php'; ?>
<div class="main">
<div class="qd_text_box">
  <div class="qd_title"><h4>扫码核销</h4></div>
  <div class="qd_desc"><?php echo $qd_desc; ?></div>
</div>
  <form name="queryForm" method="post" class="" action="?t=<?php echo time();?>" onsubmit="return startRequest(0);">
  <input type="hidden" name="txt_data" value="1">
    
    <div class="so_box" id="s11">
      <input name="name" type="text" class="txts" id="name" value="" placeholder="请输入手机" />
    </div>
    <?php if($ismas=="1"){ ?>
    <div class="so_box" id="s33">
      <input name="code" type="text" class="txts" id="code" placeholder="请输入验证码" onfocus="this.value=''" onBlur="startRequest(3)" />
      <div class="more" id="clearkey">
        <img src="inc/code.php?t=<?php echo date("Y-m-d-H-i-s",time());?>" id="Codes" onClick="this.src='inc/code.php?t='+new Date();"/>
      </div>
    </div>
    <?php }?>
    
    <div class="so_boxes">
      <input type="submit" name="button" class="buts" id="sub" value="核销">
    </div>
<?php 
  
 ?>
    <div id="tishi1" style="display:none;">请输入<?php echo $tiaojian1;?></div>
    <div id="tishi4" style="display:none;">认真输入4数字验证码</div>
</form>

<div id="scanqrcode1">
  <i class="iconfont icon-saoyisao"> </i>
  <span>扫一扫核销</span>
</div>

<?php } else {
  if($ismas=="1"){
    session_start();
    if($codes!=$_SESSION['PHP_M2T']){
      webalert("请正确输入验证码！");
    }
  }

  if(!$shuru1 || empty($shuru1)){
    webalert("请输入$tiaojian1!");
  }

  $filer = fopen($file_qd_all, "r") or  webalert('无法打开文件!');
  echo '<!--startprint--><div class="main"><div class="result">';
  //echo '<p>查询结果</p>';
  
  $a_files = file($file_qd_ok);
  $r = array();
  for($i=0; $i<count($a_files); $i++) {
    $t = str_getcsv($a_files[$i], "\t");
    $r[] = $t[1];
  }
while (!feof($filer)) {
    $ii++;
    $rows = fgets($filer);
    $rows = trim($rows);
    if ($rows) {

            $tabvs = explode("\t", $rows);
            //print_r($tabvs);
            if ("_" . $shuru1 == "_" . $tabvs[1]) {
                echo "<!-- $shuru1 == $tabvs[1] -->";
                // 查询成功后，将数据存入文件，并且提示签到成功，这样能知道签到有多少人
                $fp_qd_ok=fopen($file_qd_ok,"a+b");
                $fp_time=fopen($file_qd_time,"a+b");

               /* $data_array = array();
                while( ($data_line = fgets($fp)) !== false ) {
                  $data_array[] = trim($data_line);
                }*/
                if( in_array($shuru1, $r) ) {echo "<h4 style='font-size: 18px; text-align: center;   font-weight: 700; color: #FF5722; padding-top: 10px;'>提示：该顾客已核销过，勿需重复核销！</h4>";} else {
                  fwrite($fp_qd_ok,"$tabvs[0]\t{$shuru1}\r\n"); 
                  fwrite($fp_time,"{$time_creat}\r\n"); 

                }
                fclose($fp_qd_ok);
                fclose($fp_time);
                $iae++;
                $iaf = 0;
                echo '<div class="field">';
                echomsg($tabvs[$iaf].",核销成功!",1,"您的信息如下");
                //echo $tabvs[$iaf]."，恭喜您签到成功";
                
                foreach ($tabvs as $tabu) {
                    $iaf++;
                    $iag = $iaf - 1;
                    // echo '<td class="r">'.$tabvt["$iag"].'</td>';
                    echo '<span >' . $tabu . '</span>';
                }
                
                echo '</div>';
            }
        // }
    }
}
if($iae<1){
    
    echomsg("核销失败",0,"该顾客没有线上报名");
    
}

echo '</div>';
echo '<!--endprint-->';
fclose($filer); ?>
<div class="so_boxesd">
  <input type="button" value="返 回" class="btn btn-primary btn-block" onclick="location.href='?t=back';" id="reset">
</div>
</div>
</div>
<?php } 
} 

$etime=microtime(true);//获取程序执行结束的时间
$total=$etime-$stime;   //计算差值
//echo "<div>页面执行时间：{$total} 秒</div>";
?>
</div>
<div class="foot">
  <div class="title">
    &copy;<?php echo date('Y');?>&nbsp; <a href="http://www.ffepcn.com/" target="_blank">名家居世博园</a>
  </div> 
  <div class="span_cnzz">
      <script type="text/javascript">var cnzz_protocol = (("https:" == document.location.protocol) ? "https://" : "http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_1275932052'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s23.cnzz.com/stat.php%3Fid%3D1275932052%26show%3Dpic' type='text/javascript'%3E%3C/script%3E"));</script>
  </div>
</div>
<script src="https://lib.baomitu.com/jquery/2.1.4/jquery.min.js"></script>
<script src="inc/js/mobile-menu.js?v=<?php echo $tts;?>"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script src="inc/js/wx_share_scan.js?v=<?php echo $tts;?>"></script>
</body>
</html>